<template>
	<view>
		<uni-section title="请输入意见标题" type="line"></uni-section>
		<view class="uni-form-item uni-column">
			<uni-easyinput class="uni-mt-5" trim="all" v-model="qtitle" placeholder="请输入内容"></uni-easyinput>
		</view>
		<uni-section title="请输入意见内容" type="line"></uni-section>
		<uni-easyinput type="textarea" v-model="mycontent" placeholder="请输入内容"></uni-easyinput>
		<uni-section title="请选择意见种类" type="line">
			<uni-data-select v-model="value" :localdata="range"></uni-data-select>
		</uni-section>
		<uni-section title="请选择图片" type="line">
			<button type="primary" style="width: 500rpx;" @click="upload()">点击上传</button>
		</uni-section>
		<view>
			<view v-for="(i, index) in fileNameSt" :key="index">
				<image :src="'http://xg.kystu.cn:8085'+i"></image>
			</view>
		</view>
		<uni-section title="提交" type="line">
			<button type="primary" style="width: 500rpx;" @click="Tosubmit()">提交</button>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: 0,
				range: [{
						value: 0,
						text: "日常教学"
					},
					{
						value: 1,
						text: "生活日常"
					},
				],
				mycontent: '',
				qtitle: '',
				fileNameSt: [],
				token: '',
				url: 'http://xg.kystu.cn:8085/common/upload',
				fileName: ''
			}
		},
		methods: {
			upload() {
				var _this = this;
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						console.log(tempFilePaths);
						uni.uploadFile({
							url: _this.url, //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'user': 'test'
							},
							header: {
								'Authorization': "Bearer " + _this.token
							},
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data);
								uploadFileRes.data = JSON.parse(uploadFileRes.data);
								if (_this.fileName != null && _this.fileName != "") {
									_this.fileName = _this.fileName + ","
								}
								_this.fileName = _this.fileName + uploadFileRes.data.fileName;
								console.log(_this.fileName)
								_this.fileNameSt = _this.fileName.split(",")
								console.log(_this.fileNameSt[0])
							}
						});
					}
				});
			},
			Tosubmit() {
				var _this = this;
				uni.request({
					url: 'http://xg.kystu.cn:8085/system/suggestion',
					method: "POST",
					data: {
						title: _this.qtitle,
						mycontent: _this.mycontent,
						classone:_this.value,
						upfile: _this.fileName
				 },
					header: {
						'Authorization': "Bearer " + _this.token
					},
					success: (res) => {
						if (res.data
							.code ==
							200) {
							uni.navigateTo({
								url: '/pages/els/content/content4'
							});
						}
					}
				});
			},
			onShow() {
				var _this = this;
				uni.getStorage({
					key: 'App-Token',
					success(res) {
						_this.token = res.data;
					}
				})
			}
		}
	}
</script>

<style>

</style>
